#include "stdafx.h"
#include "CRadio.h"

NAMESPACE_CORE_BEGIN

CRadio::CRadio()
{
}

CRadio::CRadio(int_32 iX, int_32 iY, int_32 iWidth, int_32 iHeight)
	: CButtonControl(iX, iY, iWidth, iHeight)
{
}
CRadio::~CRadio()
{

}

const COID & CRadio::GetOID() const
{
	return OID_RADIO;
}

IGroup * CRadio::GetGroup()
{
	return this;
}

IControl * CRadio::GetGroupControl()
{
	return this;
}

void CRadio::MouseClick(CMouseArgument & args)
{
	if(args.m_eButton == MouseButtonLeft)
		SetChecked(true);
	CButtonControl::MouseClick(args);
}

void CRadio::OnPaintBack(IPaint * pPaint, const CRectInt32 & rcClip) const
{
	//CRectInt32 rect = GetRect();
	//pPaint->DrawRect(rect.X, rect.Y, rect.Width - 1, rect.Height - 1, 0xFFFF0000, 1.0f);
}

void CRadio::SetChecked(bool bChecked)
{
	SetGroupChecked(bChecked);
}

bool CRadio::IsChecked() const
{
	return IsGroupChecked();
}

void CRadio::CheckedChanged()
{
	Repaint();
}

void CRadio::DrawButtonIcon(IPaint * pPaint, int_32 iX, int_32 iY) const
{
	VerifyPointer(m_pIcon);
	switch(m_eIconTileMode)
	{
	case ImageTileModeV8:
		DrawIconV8(pPaint, iX, iY);
		break;
	default:
		throw CBadStateException();
	}
}
void CRadio::DrawButtonText(IPaint * pPaint, int_32 iX, int_32 iY) const
{
	pPaint->DrawString(m_text, m_text.GetLength(), iX, iY, &CSolidBrush(m_uiForeColor));
}

void CRadio::DrawIconV8(IPaint * pPaint, int_32 iX, int_32 iY) const
{
	VerifyPointer(m_pIcon);
	int_32 iTileW = m_pIcon->GetWidth();
	int_32 iTileH = m_pIcon->GetHeight() >> 3;
	int_32 iTileY = 0;

	if(m_bDisabled)
		iTileY = iTileH * 3;
	else if(m_bMouseDownL)
		iTileY = iTileH * 2;
	else if(m_bMouseHoving)
		iTileY = iTileH;
	else
		iTileY = 0;

	pPaint->DrawImage(m_pIcon,
		CRectFloat32((float_32)iX, (float_32)iY, (float_32)iTileW, (float_32)iTileH),
		CRectFloat32((float_32)0, (float_32)iTileY, (float_32)iTileW, (float_32)iTileH));

	if(m_bChecked)
	{
		pPaint->DrawImage(m_pIcon,
			CRectFloat32((float_32)iX, (float_32)iY, (float_32)iTileW, (float_32)iTileH),
			CRectFloat32((float_32)0, (float_32)iTileY + iTileH * 4, (float_32)iTileW, (float_32)iTileH));
	}
}
NAMESPACE_CORE_END
